package com.example.mall.web.controller;

import com.example.mall.domain.EmailNotifications;
import com.example.mall.dto.EmailNotificationsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.EmailNotificationsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IEmailNotificationsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emailNotifications")
public class EmailNotificationsController {

    @Autowired
    public IEmailNotificationsService emailNotificationsService;

    /**
     * 分页查询邮件通知表信息
     * @param emailNotificationsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询邮件通知表信息",notes = "分页查询邮件通知表信息",httpMethod = "GET")
    public JSONResult queryPage(EmailNotificationsQuery emailNotificationsQuery){
        PageDTO<EmailNotificationsDto> emailNotificationsDtoPageDTO = emailNotificationsService.queryPage(emailNotificationsQuery);
        return JSONResult.success("查询成功",emailNotificationsDtoPageDTO);
    }

    /**
     * 根据id查询邮件通知表信息
     * @param emailId
     * @return
     */
    @GetMapping("query/{emailId}")
    @ApiOperation(value = "根据id查询邮件通知表信息",notes = "根据id查询邮件通知表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("emailId")Long emailId){
        //1.根据id查询用户信息
        if (emailId == null){
            throw new GlobalCustomerException(ErrorEnumCode.EMAILID_NOT_ID);
        }
        EmailNotifications emailNotifications = emailNotificationsService.getById(emailId);
        return JSONResult.success("查询成功",emailNotifications);
    }

    /**
     * 根据id查询邮件通知表信息
     * @param emailId
     * @return
     */
    @GetMapping("queryEmailNotificationsById/{emailId}")
    @ApiOperation(value = "根据id查询邮件通知表信息",notes = "根据id查询邮件通知表信息",httpMethod = "GET")
    public JSONResult queryEmailNotificationsById(@PathVariable("emailId")Long emailId){
        //1.根据id查询用户信息
        if (emailId == null){
            throw new GlobalCustomerException(ErrorEnumCode.EMAILID_NOT_ID);
        }
        EmailNotifications emailNotifications = emailNotificationsService.queryEmailNotificationsById(emailId);
        return JSONResult.success("查询成功",emailNotifications);
    }

    /**
     * 查询全部邮件通知表信息
     * @param
     * @return
     */
    @GetMapping("queryEmailNotificationsList")
    @ApiOperation(value = "查询全部邮件通知表信息",notes = "查询全部邮件通知表信息",httpMethod = "GET")
    public JSONResult queryEmailNotificationsList(){
        List<EmailNotifications> emailNotifications = emailNotificationsService.queryEmailNotificationsList();
        return JSONResult.success("查询成功",emailNotifications);
    }

    /**
     * 新增邮件通知表
     * @param emailNotificationsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增邮件通知表",notes = "新增邮件通知表",httpMethod = "POST")
    public JSONResult insert(@RequestBody EmailNotificationsDto emailNotificationsDto){
        emailNotificationsService.insert(emailNotificationsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改邮件通知表信息
     * @param emailNotificationsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改邮件通知表信息",notes = "修改邮件通知表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody EmailNotificationsDto emailNotificationsDto){
        emailNotificationsService.update(emailNotificationsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除邮件通知表信息
     * @param emailId
     * @return
     */
    @PostMapping("delete/{emailId}")
    @ApiOperation(value = "删除邮件通知表信息",notes = "删除邮件通知表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("emailId") Long emailId) {
        emailNotificationsService.delete(emailId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除邮件通知表信息
     * @param emailIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除邮件通知表信息",notes = "批量删除邮件通知表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> emailIds) {
        emailNotificationsService.deleteBatch(emailIds);
        return JSONResult.success("批量删除成功");
    }
}
